package luj.tool.jnproxyan.framework.spring;

import luj.bean.api.BeanContext;
import luj.bean.api.LujBean;
import luj.data.api.DataContext;
import luj.data.api.LujData;
import luj.net.api.LujNet;
import luj.net.api.NetContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.support.GenericApplicationContext;

@ComponentScan("luj.tool.jnproxyan")
public class SpringContextMaker {

  public GenericApplicationContext make() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(SpringContextMaker.class);

    ctx.registerBean(NetContext.class, () -> LujNet.create(ctx));
    ctx.registerBean(BeanContext.class, LujBean::start);
    ctx.registerBean(DataContext.class, LujData::start);

    ctx.refresh();

    return ctx;
  }
}
